﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Windows8Accelerator.Core.Xaml.Controls
{
    public class SuperMargin
    {
        public SuperMargin(string text)
        {
            if (text.Contains(","))
            {
                var parts = text.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries);
                Left = new ItemLength(parts[0]);
                if (parts.Length > 1)
                    Top = new ItemLength(parts[1]);
                if (parts.Length > 2)
                    Right = new ItemLength(parts[2]);
                if (parts.Length > 3)
                    Bottom = new ItemLength(parts[3]);

                if (parts.Length == 2)
                {
                    Bottom = Top;
                    Right = Left;
                }
            }
            else
            {
                Left = Top = Right = Bottom = new ItemLength(text);            
            }
        }

        public SuperMargin(ItemLength left, ItemLength top, ItemLength right, ItemLength bottom)
        {
            Left = left;
            Top = top;
            Right = right;
            Bottom = bottom;
        }

        public static SuperMargin Zero
        {
            get
            {
                return new SuperMargin("0");
            }
        }

        public override string ToString()
        {
            return string.Format("{0},{1}",Left,Top, Right, Bottom);
        }

        public ItemLength Left { get; set; }

        public ItemLength Top { get; set; }

        public ItemLength Right { get; set; }

        public ItemLength Bottom { get; set; }
    }
}
